package yxy.game.pm2.active.module;

import yxy.apple.util.PubSub.MethodSubscriber;
import yxy.apple.util.PubSub.SubscriptionMethod;
import yxy.game.pm2.bean.Currency;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.bean.pubsub.CurrencyPublisher;
import yxy.game.pm2.bean.pubsub.CurrencyPublisher.CurrencySubscription;
import yxy.game.pm2.module.tip.TipHandle;
import yxy.game.pm2.module.tip.TipType;

import java.util.HashSet;
import java.util.Set;

public class TipSubscriber_夺宝 extends MethodSubscriber {

	static private TipSubscriber_夺宝 instance;

	public static TipSubscriber_夺宝 getInstance() {
		if (instance == null) {
			instance = new TipSubscriber_夺宝();
			instance.init();
		}
		return instance;
	}

	private void init() {
		CurrencyPublisher.getInstance().subscribe(this);
	}

	private TipSubscriber_夺宝() {
	}

	@SubscriptionMethod(Type = CurrencySubscription.class)
	public void receive(CurrencySubscription subscription) {
//		System.err.println("订阅更新Task");
		String playerCode = subscription.getPlayerCode();
		if (!subscription.checkTypes(allowType())) {
			return;
		}
		new TipHandle().updateTip(playerCode, TipType.活动_夺宝宝箱奖励, check(playerCode));
	}

	private boolean check(String playerCode) {
		long num1033 = Currency.number(playerCode, CurrencyType.CT_物品, 1033,false);
		long num1034 = Currency.number(playerCode, CurrencyType.CT_物品, 1034,false);
	
		return num1033 > 0 || num1034 > 0 ;
	}

	private Set<CurrencyType> allowTypes;

	private Set<CurrencyType> allowType() {
		if (allowTypes != null) {
			return allowTypes;
		}
		allowTypes = new HashSet<>();

		CurrencyType type = CurrencyType.CT_物品;
		allowTypes.add(type);
		return allowTypes;
	}
}
